package singleton.chocolateFactory.boiler;

public class ChocolateBoiler {
    private boolean empty;
    private boolean boiled;

    /* private Constructor */
    private ChocolateBoiler()
    {
        empty = true;
        boiled = false;
    }

    /* {static} uniqueInstance */
    private static ChocolateBoiler chocolateBoiler;

    /* {static} getInstance() */
    public static ChocolateBoiler getChocolateBoiler() {
        if (chocolateBoiler == null)
        {
            chocolateBoiler = new ChocolateBoiler();
            System.out.println("Creating a new Boiler");
        }
        else System.out.println("A Boiler exists. ( The Boiler class is a singleton. )");
        return chocolateBoiler;
    }

    public void fill()
    {
        if (isEmpty())
        {
            empty = false;
            boiled = false;
            System.out.println("Loaded with milk and chocolate");
        }
    }

    public void drain()
    {
        if (! isEmpty() && isBoiled())
        {
            System.out.println("Shoot out the boiling milk and chocolate");
            empty = true;
        }
    }

    public void boil()
    {
        if (! isEmpty() && ! isBoiled())
        {
            System.out.println("Heating up...");
            boiled = true;
        }
    }

    public boolean isEmpty()
    {
        return empty;
    }

    public boolean isBoiled()
    {
        return boiled;
    }

}
